package com.formula.propertyshop.model;

import java.io.Serializable;
import java.text.DecimalFormat;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
@JsonIgnoreProperties(ignoreUnknown=true)
public class Property implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@JsonProperty(value="id",required=true)
	private int id;
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	@JsonProperty("thumbnail")
	private String imgThumbnailUrl;
	@JsonProperty("name")
	private String name;
	@JsonProperty("excerpt")
	private String excerpt;
	@JsonProperty("price")
	private String price;
	@JsonProperty("bedrooms")
	private String bedrooms;
	@JsonProperty("bathrooms")
	private String bathrooms;
	@JsonProperty("location")
	private String location;
	@JsonProperty("gallery")
	private String[] imgGalleryUrl;
	
	public String[] getImgGalleryUrl() {
		return imgGalleryUrl;
	}
	public String getImgThumbnailUrl() throws Exception{
		if(imgThumbnailUrl.startsWith("false"))
			throw new IllegalArgumentException();
		return imgThumbnailUrl;
	}
	public void setImgUrl(String imgUrl) {
		this.imgThumbnailUrl = imgUrl;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPrice() {
		return price;
	}
	public String getPriceFormat(){
		try{
			Double dPrice = Double.parseDouble(price);
			DecimalFormat formatter = new DecimalFormat("###,###,###.##");
			return "$"+formatter.format(dPrice);	
		}catch(Exception e){
			
		}		
		return price;
	}
	public void setPrice(String price) {
		this.price = price;
	}
	public String getBedrooms() {
		return bedrooms;
	}
	public void setBedrooms(String street) {
		this.bedrooms = street;
	}
	public String getLocation() {
		return location;
	}
	public String getBathrooms() {
		return bathrooms;
	}
	public void setBathrooms(String address) {
		this.bathrooms = address;
	}
	public String getExcerpt() {
		if(excerpt!=null)
			excerpt = excerpt.replaceAll("\r\n", " ");
		return excerpt;
	}
	public void setExcerpt(String excerpt) {
		this.excerpt = excerpt;
	}
	public String getTenure(){
		String tenure = "";
		try {
			tenure = excerpt.split("\r\n", 2)[1];
		}
		catch (Exception e){}
		
		return tenure;
	}
	public String getPropertyType(){
		String PropertyType = "";
		try {
			PropertyType = excerpt.split("\r\n", 2)[0];
		}
		catch (Exception e){}
		
		return PropertyType;
	}
}
